const { remotePathPrefix } = require('../deployment.conf.js')
let outputRoot = 'dist'
if (process.env.npm_lifecycle_event.indexOf('weapp') > 0) {
  outputRoot = 'dist_weapp'
} else if (process.env.npm_lifecycle_event.indexOf('h5') > 0) {
  outputRoot = 'dist_h5'
}
const express = require('express')
const axios = require('axios')
const appConfig = require('./router/config')
const bodyParser = require('body-parser')
const apiRoutes = express.Router()
const devRequest = require('./../src/api/devApi/devRequest')
const os = require('os')
var ifaces = os.networkInterfaces();
var ip = ''
for (var dev in ifaces) {
    var alias = 0;
    ifaces[dev].forEach(function (details) {
        if (details.family == 'IPv4' && dev == 'WLAN') {
            ip = details.address
            ++alias;

        }
    });
}
console.log('ip:' + ip)

const config = {
  projectName: 'shopRecuit',
  date: '2019-3-26',
  designWidth: 750,
  deviceRatio: {
    '640': 2.34 / 2,
    '750': 1,
    '828': 1.81 / 2
  },
  sourceRoot: 'src',
  outputRoot: 'dist',
  outputRoot: outputRoot,
  plugins: {
    babel: {
      sourceMap: true,
      presets: [
        ['env', {
          modules: false
        }]
      ],
      plugins: [
        'transform-decorators-legacy',
        'transform-class-properties',
        'transform-object-rest-spread'
      ]
    }
  },
  defineConstants: {
    LOCATION_APIKEY: JSON.stringify('JLJBZ-T5ZL2-BELUZ-C6DNP-HU4M5-SJBAG')
  },
  copy: {
    patterns: [
    ],
    options: {
    }
  },
  weapp: {
    module: {
      postcss: {
        autoprefixer: {
          enable: true,
          config: {
            browsers: [
              'last 3 versions',
              'Android >= 4.1',
              'ios >= 8'
            ]
          }
        },
        pxtransform: {
          enable: true,
          config: {

          }
        },
        url: {
          enable: true,
          config: {
            limit: 10240 // 设定转换尺寸上限
          }
        },
        cssModules: {
          enable: false, // 默认为 false，如需使用 css modules 功能，则设为 true
          config: {
            namingPattern: 'module', // 转换模式，取值为 global/module
            generateScopedName: '[name]__[local]___[hash:base64:5]'
          }
        }
      }
    }
  },
  h5: {
    output: {
      filename: 'js/[name].[hash:8].js',
      chunkFilename: 'js/[name].[chunkhash:8].js'
    },
    router: {
      mode: 'hash' // 或者是 'browser'
    },
    devServer: {
      host: ip,
      port: 8090,
      before(apiRoutes) {
        const urlencodedParser = bodyParser.urlencoded({ extended: false })
        apiRoutes.post('/worker/person', urlencodedParser, devRequest.workerPerson)
        apiRoutes.post('/theme', urlencodedParser, devRequest.theme)
        apiRoutes.post('/wechat/webEmpower/jsConfig', urlencodedParser, devRequest.shareConfig)
        apiRoutes.post('/worker/jobList', urlencodedParser, devRequest.job)
        apiRoutes.get('/tag', urlencodedParser, devRequest.tag)
        apiRoutes.post('/company/describe', urlencodedParser, devRequest.describe)
        apiRoutes.get('/industry', urlencodedParser, devRequest.industry)
        apiRoutes.get('/area', urlencodedParser, devRequest.area)
        apiRoutes.post('/worker/job/star', urlencodedParser, devRequest.star)
        apiRoutes.get('/worker/job/show', devRequest.jobDetail)
        apiRoutes.post('/worker/company', urlencodedParser, devRequest.company)
        apiRoutes.post('/worker/show', urlencodedParser, devRequest.resumeShow)
        apiRoutes.post('/worker/showDemand', urlencodedParser, devRequest.showDemand)
        apiRoutes.post('/worker/me', urlencodedParser, devRequest.wokerMe)
        apiRoutes.post('/company/me', urlencodedParser, devRequest.companyMe)
        apiRoutes.post('/worker/job/starred', urlencodedParser, devRequest.workerStarred)
        apiRoutes.post('/worker/job/applied', urlencodedParser, devRequest.workerApplied)
        apiRoutes.post('/position', urlencodedParser, devRequest.positionList)
        apiRoutes.post('/worker/demand', urlencodedParser, devRequest.editDemand)
        apiRoutes.post('/worker/resume', urlencodedParser, devRequest.editResume)
        apiRoutes.post('/company/company/license', urlencodedParser, devRequest.license)
        apiRoutes.post('/company/company/showLicense', urlencodedParser, devRequest.showLicense)
        apiRoutes.post('/company/resume', urlencodedParser, devRequest.companyResume)
        apiRoutes.post('/company/resume/item', urlencodedParser, devRequest.companyResumeItem)
        apiRoutes.post('/company/resume/refuse', urlencodedParser, devRequest.refuseResume)
        apiRoutes.post('/company/resume/call', urlencodedParser, devRequest.callResume)
        apiRoutes.post('/company/company/show', urlencodedParser, devRequest.companyShow)
        apiRoutes.post('/company/job/list', urlencodedParser, devRequest.companyJobList)
        apiRoutes.post('/company/job/describe', urlencodedParser, devRequest.editJob)
        apiRoutes.post('/company/job/show', urlencodedParser, devRequest.companyjobDetail)
        apiRoutes.post('/company/job/offline', urlencodedParser, devRequest.companyjobDetail)
        apiRoutes.post('/worker/job/apply', urlencodedParser, devRequest.jobApply)
        apiRoutes.post('/company/company/list', urlencodedParser, devRequest.myCompany)
        apiRoutes.post('/worker/wallet', urlencodedParser, devRequest.workerWallet)
        apiRoutes.post('/worker/wallet/log', urlencodedParser, devRequest.workerWalletLog)
        apiRoutes.post('/company/resume/buy', urlencodedParser, devRequest.buyResume)
        apiRoutes.post('/worker/job/complaint', urlencodedParser, devRequest.complaint)
        apiRoutes.post('/company/resume/order', urlencodedParser, devRequest.resumeOrder)
        apiRoutes.post('/company/wallet/log', urlencodedParser, devRequest.walletLog)
        apiRoutes.post('/index/resolveSaas', urlencodedParser, devRequest.getSaas)
        apiRoutes.get('/worker/apply-withdraw', urlencodedParser, devRequest.applyWithdraw)
        apiRoutes.post('/worker/resumev2', urlencodedParser, devRequest.resumev2)
        apiRoutes.post('/poster/companyPoster', urlencodedParser, devRequest.CompanyPoster)
        apiRoutes.post('/poster/JobPoster', urlencodedParser, devRequest.JobPoster)
        apiRoutes.post('/worker/protocol', urlencodedParser, devRequest.protocol)
        apiRoutes.post('/company/job/resumePoolCategory', urlencodedParser, devRequest.resumePoolCategory)
        apiRoutes.post('/company/job/resumePool', urlencodedParser, devRequest.resumePool)
        //phoneLogin.js
        apiRoutes.post('/login', urlencodedParser, devRequest.phoneLogin)
        apiRoutes.post('/login/wechatMPAuthorize', urlencodedParser, devRequest.userInfo)
        apiRoutes.post('/company/job/topList', urlencodedParser, devRequest.topList)
        apiRoutes.post('/company/job/buyTopList', urlencodedParser, devRequest.buyTopList)
        apiRoutes.post('/wap/user/verifyPhone', urlencodedParser, devRequest.verifyPhone)
        apiRoutes.get('/oss/sign', urlencodedParser, devRequest.ossSign)
        apiRoutes.post('/company/wallet/recharge/:aid', urlencodedParser, devRequest.recharge)
        apiRoutes.post('/company/member/memberList', urlencodedParser, devRequest.memberList)
        apiRoutes.post('/company/member/buyMember', urlencodedParser, devRequest.buyMember)
        apiRoutes.post('/company/member/buyMemberMenu', urlencodedParser, devRequest.buyMemberMenu)
        apiRoutes.post('/poster/indexTranmistPoster', urlencodedParser, devRequest.indexTranmistPoster)
        apiRoutes.post('/poster/companyTranmistPoster', urlencodedParser, devRequest.companyTranmistPoster)
        apiRoutes.post('/poster/jobTranmistPoster', urlencodedParser, devRequest.jobTranmistPoster)
        apiRoutes.post('/worker/personInfo', urlencodedParser, devRequest.personInfo)
        apiRoutes.post('/worker/workerStatus', urlencodedParser, devRequest.workerStatus)
        apiRoutes.post('/worker/topiceEntrance', urlencodedParser, devRequest.topiceEntrance)
        apiRoutes.post('/worker/customerConfig', urlencodedParser, devRequest.customerConfig)
        apiRoutes.post('/worker/redBag', urlencodedParser, devRequest.redBag)
        apiRoutes.post('/worker/getResumeRedBag', urlencodedParser, devRequest.getResumeRedBag)
      }
    },
    publicPath: process.env.NODE_ENV === 'production' ? `https://bcy-h5.oss-cn-hangzhou.aliyuncs.com/${remotePathPrefix}/` : '/',
    // publicPath: '/',
    staticDirectory: 'static',
    module: {
      postcss: {
        autoprefixer: {
          enable: true,
          config: {
            browsers: [
              'last 3 versions',
              'Android >= 4.1',
              'ios >= 8'
            ]
          }
        },
        cssModules: {
          enable: false, // 默认为 false，如需使用 css modules 功能，则设为 true
          config: {
            namingPattern: 'module', // 转换模式，取值为 global/module
            generateScopedName: '[name]__[local]___[hash:base64:5]'
          }
        }
      }
    },
    esnextModules: ['bcy-ui, bcy-api'],
    performance: {
      hints: false
    }
  }
}

module.exports = function (merge) {
  if (process.env.NODE_ENV === 'development') {
    return merge({}, config, require('./dev'))
  }
  return merge({}, config, require('./prod'))
}
